package com.bootcamp.javase2.io;

import java.io.FileOutputStream;
import java.io.IOException;

/**
 * @program: IOCode
 * @description: arrange letters to files according to their POS.
 * @author: Keyu Li
 * @create: 2021-09-09 20:20
 **/

public class arrangeLetterFile {
    static final String[] WORDS = {"verb:eat","verb:drink","verb:sleep","verb:play","noun:rice","noun:meat","noun:hand","noun:hair"};

    public static void main(String[] args) throws IOException {
        // create verb.txt and noun.txt
        FileOutputStream inVerb = new FileOutputStream("verb.txt");
        FileOutputStream inNoun = new FileOutputStream("noun.txt");
        //write
        for (String word : WORDS) {
            if (word.startsWith("verb")){
                inVerb.write(word.getBytes());
                inVerb.write(System.lineSeparator().getBytes());
            }else if (word.startsWith("noun")){
                inNoun.write(word.getBytes());
                inNoun.write(System.lineSeparator().getBytes());
            }else
                continue;
        }
        //close
        inVerb.close();
        inNoun.close();
        // print
        System.out.println("-----------VERB---------");
        PrintFile.print("verb.txt");
        System.out.println("-----------NOUN---------");
        PrintFile.print("noun.txt");
    }
}
